﻿Public Class Login2
    Dim ja As Int16 = 1
    Dim tbl As New DataTable
    Private Sub Login2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        tbl = cmd.ExecuteDataTable("SELECT e.emp_id,e.emp_name ,u.user_id, u.username,u.password,ut.user_type_id,ut.user_type FROM employee_tbl e INNER JOIN user_tbl u ON e.EMP_ID=u.EMP_ID INNER JOIN user_type_tbl ut on u.user_type_id=ut.user_type_id ")
    End Sub

    Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
        Dim i As Integer = 0
        Dim msg As String = ""
        If ja > 5 Then
            MessageBox.Show("You enter wrong username or password more than 5 times this program quit now")
            Me.Close()
        End If
        ja = ja + 1
        If txtuser.Text = "" Or txtpwd.Text = "" Then
            MessageBox.Show("Please input username and password")
            Exit Sub
        ElseIf txtuser.Text <> "" And txtpwd.Text <> "" Then

            For i = 0 To tbl.Rows.Count - 1
                If LCase(tbl.Rows(i).Item(3)) = LCase(txtuser.Text) And tbl.Rows(i).Item(4) = txtpwd.Text Then
                    MessageBox.Show("Login Success")
                    'Me.Visible = False
                    frmworktime.emp_id = tbl.Rows(i).Item(0)
                    frmworktime.emp_name = tbl.Rows(i).Item(1)
                    frmworktime.Show()
                    msg = ""
                    Me.Close()
                    Exit For

                Else
                    msg = "Login fail"
                End If
            Next
            If msg <> "" Then
                MessageBox.Show(msg)
            End If

        Else
            MessageBox.Show("Login Fail")
        End If
    End Sub
End Class